package com.xtravel.common.widget;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.xtravel.R;

/**
 * Created by Administrator on 2015/9/1.
 */
public class GestureImageLayout extends RelativeLayout {

    public GestureImageLayout(Context context, String imageUrl) {
        super(context);

        LayoutParams rparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        setLayoutParams(rparams);

        AsyncGestureImageView imageView = new AsyncGestureImageView(context, 0.6f, 10f);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        addView(imageView);

        View vLoading = addLoadingView();
        imageView.setId(R.id.ivGesture);
        imageView.setLoadingView(vLoading);
        imageView.setImageUrl(imageUrl);
    }

    private View addLoadingView() {
        ImageView ivLoading = new ImageView(getContext());
        ivLoading.setImageResource(R.drawable.loading_bg);

        /*
        Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.loading);
        LinearInterpolator lir = new LinearInterpolator();
        anim.setInterpolator(lir);
        ivLoading.startAnimation(anim);
        */

        LayoutParams layoutParams =
                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        ivLoading.setLayoutParams(layoutParams);

        addView(ivLoading);
        return ivLoading;
    }

}
